import * as echarts from 'echarts';
import Vue from 'vue';



/**
 * 组件命名空间
 */
export namespace N_cBaseChart {
  /**
 * 图表配置接口 - 根据help.md中的JSON结构定义
 */
  export interface ChartConfig {
    // 图表基础配置
    chart: {
      id: string;
      type: string;
      title: {
        text: string;
        subtext?: string;
        left?: string;
      };
      width?: string;
      height?: string;
      theme?: string;
    };

    // 数据配置
    data: {
      source: {
        type: 'static' | 'scada-api' | 'database';
        endpoint?: string;
        auth?: {
          type: string;
          token: string;
        };
        refreshInterval: number;
        maxPoints: number;
      };
      mapping: {
        xAxis: string;
        series: Array<{
          name: string;
          field: string;
          code: string;
          unit?: string;
          color?: string;
        }>;
      };
      transform: {
        deduplication: {
          enabled: boolean;
          threshold: number;
          strategy: 'average' | 'min' | 'max' | 'first' | 'last';
        };
        aggregation?: {
          enabled: boolean;
          interval: number;
          method: 'avg' | 'sum' | 'max' | 'min';
        };
      };
    };

    // 坐标轴配置
    xAxis: {
      type: string;
      // name: string;
      // nameLocation: string;
      // 其他ECharts轴配置
      [key: string]: any;
    };

    yAxis: {
      type: string;
      name: string;
      nameLocation: string;
      // 其他ECharts轴配置
      [key: string]: any;
    };

    // 系列配置
    series: Array<{
      name: string;
      type: string;
      smooth?: boolean;
      symbol?: string;
      symbolSize?: number;
      lineStyle?: object;
      itemStyle?: object;
      areaStyle?: object;
      showSymbol?: boolean;
      animation?: {
        enabled: boolean;
        duration: number;
        easing: string;
      };
      markLine?: object;
    }>;

    // 其他ECharts配置
    tooltip?: object;
    legend?: object;
    grid?: object;
    toolbox?: object;
    dataZoom?: Array<object>;
    animation?: object;
    backgroundColor?: string;
    textStyle?: object;
  }

  /**
   * 组件Props接口
   */
  export interface ChartComponentProps {
    config: ChartConfig; // 图表配置
    autoInit?: boolean; // 是否自动初始化
    theme?: string; // 主题
  }

  /**
   * 组件暴露的方法接口
   */
  export interface ChartComponentExposed {
    initChart: () => void; // 初始化图表
    updateData: (data: any) => void; // 手动更新数据
    refresh: () => void; // 刷新图表
    resize: () => void; // 调整尺寸
    dispose: () => void; // 销毁图表
    getInstance: () => echarts.ECharts | null; // 获取ECharts实例
  }

  export interface scadaData {
    t: string;
    v: number;
    label: string;
  }

  export interface ChartData {
    code: string;
    active: boolean;
    values: scadaData[];
  }

  /**
   * 数据降重配置
   */
  export interface DeduplicationConfig {
    enabled: boolean;
    threshold: number;
    strategy: 'average' | 'min' | 'max' | 'first' | 'last';
  }

  /**
   * 数据聚合配置
   */
  export interface AggregationConfig {
    enabled: boolean;
    interval: number;
    method: 'avg' | 'sum' | 'max' | 'min';
  }

  /**
   * 数据映射配置
   */
  export interface DataMapping {
    xAxis: string;
    series: Array<{
      name: string;
      field: string;
      unit?: string;
      color?: string;
    }>;
  }

  /**
   * 数据源配置
   */
  export interface DataSourceConfig {
    type: 'static' | 'scada-api' | 'database';
    endpoint?: string;
    auth?: {
      type: string;
      token: string;
    };
    refreshInterval: number;
    maxPoints: number;
  }
  export interface cBaseChart extends Vue {
    config: ChartConfig; // 图表配置
    autoInit: boolean; // 是否自动初始化
    initChart: () => void; // 初始化图表
    updateData: (data: any) => void; // 手动更新数据
    refresh: () => void; // 刷新图表
    resize: () => void; // 调整尺寸
    dispose: () => void; // 销毁图表
    getInstance: () => echarts.ECharts | null; // 获取ECharts实例
  }
}
